package com.googlecode.tda367.denty.core.level;

import org.newdawn.slick.SlickException;
import org.newdawn.slick.tiled.TiledMap;

import com.googlecode.tda367.denty.core.camera.Camera;
import com.googlecode.tda367.denty.core.camera.MovingCamera;
import com.googlecode.tda367.denty.core.dynamicbody.Key;
import com.googlecode.tda367.denty.core.dynamicbody.Lock;
import com.googlecode.tda367.denty.core.dynamicbody.SimpleEnemy;
import com.googlecode.tda367.denty.core.dynamicbody.SpikeyEnemy;

public class PuzzleLevel extends AbstractLevel {
	
	private Camera camera;
	private String tiledMapPath;
	private TiledMap map;
	
	public PuzzleLevel() {
		this.tiledMapPath = "res/lvl/denty_puzzlelevel1.tmx";
		try {
			this.map = new TiledMap(this.tiledMapPath);
		} catch (SlickException e) {
			e.printStackTrace();	
		}
		this.parseTiledMap(this.map);
		
		this.camera = new MovingCamera(this.getWidth(), this.getHeight());
		
				
		//Place lock and key
		Key key = new Key(this.getWorld(), 108f, 35f);
		Lock lock = new Lock(this.getWorld(), 119.5f, 47f);
		
		this.addDynamicBody(key);
		this.addDynamicBody(lock);
		
		SimpleEnemy enemy1 = new SimpleEnemy(12f, 30f, this.getWorld());
		enemy1.setXBounds(11f, 22f);
		this.addDynamicBody(enemy1);
		SpikeyEnemy enemy2;
		for(int i=1;i<=5;i++){
			enemy2 = new SpikeyEnemy(4*i+50f, 47, this.getWorld());
			enemy2.setXBounds(50f, 104f);
			this.addDynamicBody(enemy2);
		}
		
		addBlocks(1.5f, 41f, 3);
		addBlocks(2f, 40f, 2);
		
		addBlocks(8.5f, 7f, 3);
		addBlocks(9f, 6f, 2);
		
	}
		
	@Override
	public String getTiledMapPath() {
		return this.tiledMapPath;
	}

	private void addBlocks(float x, float y, int n){
		for(int i=0; i<n; i++){
				this.newThrowableBlock(i+x+0.5f, y+0.5f);
		}
	}
	
	
	@Override
	public Camera getCamera() {
		return this.camera;
	}

	@Override
	public int getHeight() {
		return this.map.getHeight();
	}

	@Override
	public int getWidth() {
		return this.map.getWidth();
	}

	@Override
	public int getDentyStartX() {
		
		return 1;
	}

	@Override
	public int getDentyStartY() {
		
		return 47;
	}

	@Override
	public int getGoalX() {
		
		return 123;
	}

	@Override
	public int getGoalY() {
		
		return 46;
	}

	@Override
	public int getMaxAvailableBlocks() {
		
		return 30;
	}

	@Override
	public int getBlocksAvailableFromStart() {
		
		return 3;
	}

}
